import {
	defineStore
} from "pinia";
import {
	ref
} from "vue";

const uniIdCo = uniCloud.importObject('uni-id-co');

export const useUserStore = defineStore("user", () => {
	const isLogin = ref(false);

	const setIsLogin = (value) => {
		isLogin.value = value;
	};


	const fetchLogout = async () => {
		const response = await uniIdCo.logout();
		if (response.errCode == 0) {
			setIsLogin(false);
			uni.clearStorageSync();
			return Promise.resolve(response);
		} else {
			return Promise.reject();
		}
	};

	return {
		isLogin,
		setIsLogin,
		fetchLogout
	}
}, {
	unistorage: true
});